package com.donn.securitycontrolplatform.userrole.controller;


import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.userrole.entity.TUserRole;
import com.donn.securitycontrolplatform.userrole.service.ITUserRoleService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户和角色关联表 前端控制器
 * </p>
 *
 * @author zhenglixiang
 * @since 2022-06-10
 */
@RestController
@RequestMapping("/scp/api/user/role")
@Tag(name = "user-role-controller", description = "用户绑定角色接口")
public class TUserRoleController {

    @Autowired
    ITUserRoleService service;

    @ApiOperation(value = "新增用户角色关联")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色Id"),
            @ApiImplicitParam(name = "userId", value = "用户Id")
    })
    @PostMapping("/add")
    @ResponseBody
    public Result add(@RequestBody TUserRole userRole) {

        return service.insertUserRole(userRole);
    }


    @ApiOperation(value = "修改用户角色关联")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色Id"),
            @ApiImplicitParam(name = "userId", value = "用户Id")
    })
    @PutMapping("/update")
    @ResponseBody
    public Result update(@RequestBody TUserRole userRole) {
        return service.updateUserRole(userRole);
    }

    @ApiOperation(value = "删除用户角色关联")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam Long userId) {
        return service.deleteUserRole(userId);
    }


    @ApiOperation(value = "角色标签关联信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id")
    })
    @GetMapping("/get")
    @ResponseBody
    public Result get(@RequestParam Long userId) {
        return service.getUserRoleById(userId);
    }
}
